//189000561朱一月
let ad_width = "100px";
let ad_height = "250px";
let ad_img = "img/ad1.jpg";
let close_img = "img/close.png";
let ad_img2 = "img/ad2.jpg";

//创建广告容器的 div
let ad_left = document.createElement("div");
ad_left.style.width = ad_width;
ad_left.style.height = ad_height;
ad_left.style.padding = "0px";
ad_left.style.position = "absolute";//容器绝对定位
ad_left.style.left = "30px";
ad_left.style.top = "20px";


//创建 img 元素，并加入到 ad_left 中，作为广告图片
let adimg = document.createElement("img");
adimg.src = ad_img;
ad_left.appendChild(adimg);

//创建关闭按钮，并加入到 ad_left 中
let closeimg = document.createElement("img");
closeimg.src = close_img;
closeimg.style.width = "50px";
closeimg.style.position = "relative";//相对于容器定位
closeimg.style.left = "50px";
closeimg.style.top = "-20px";
closeimg.style.cursor = "pointer";
ad_left.appendChild(closeimg);//将关闭按钮作为子节点添加到容器中


//将 ad_left 添加到 html 中
document.documentElement.appendChild(ad_left);


//添加监听事件，实现关闭广告功能
ad_left.addEventListener("click", function () {
    this.style.display = "none";
});


//实现对联广告随滚动条移动
window.addEventListener("scroll", function () {
    var st1 = document.documentElement.scrollTop || document.body.scrollTop;
    ad_left.style.top = (st1 + 20) + "px";
});


//实现右侧广告
let ad_right = ad_left.cloneNode(true);//克隆左边广告
//添加一个setInterval方法刷新右边广告位置
setInterval(function () {
    ad_right.style.left = window.innerWidth - 150 + "px";//右边广告左边距为屏幕显示区域宽度-150px
}, 1)
//将 ad_right 添加到 html 中
document.documentElement.appendChild(ad_right);
ad_right.addEventListener("click", function () {
    this.style.display = "none";
});

window.addEventListener("scroll", function () {
    var st1 = document.documentElement.scrollTop || document.body.scrollTop;
    ad_right.style.top = (st1 + 20) + "px";
});


//创建底部广告盒子
let ad_bottom = document.createElement("div");
ad_bottom.style.border = "1px solid blue";
ad_bottom.style.width = "300px";
ad_bottom.style.height = "250px";
ad_bottom.style.padding = "0px";
ad_bottom.style.position = "absolute";
ad_bottom.style.bottom = "-250px";
ad_bottom.style.left = window.innerWidth - 319 + "px";


let Up = setInterval(moveUp, 20);//调用mvoeUp
//缓慢从屏幕左下角上移出现
function moveUp() {
    let speed = 2;
    let bottom = parseInt(ad_bottom.style.bottom) + speed;
    ad_bottom.style.bottom = bottom + "px";
    if (bottom >= 0)
        clearInterval(Up);
}


let adimg2 = document.createElement("img");
adimg2.src = ad_img2;
ad_bottom.appendChild(adimg2);

let closeimg2 = document.createElement("img");
closeimg2.src = close_img;
closeimg2.style.width = "50px";
closeimg2.style.position = "relative";
closeimg2.style.left = "250px";
closeimg2.style.top = "-256px";
closeimg2.style.cursor = "pointer";
ad_bottom.appendChild(closeimg2);
document.documentElement.appendChild(ad_bottom);

ad_bottom.addEventListener("click", function () {
    this.style.display = "none";
});

window.addEventListener("scroll", function () {
    var st1 = document.documentElement.scrollTop || document.body.scrollTop;
    ad_bottom.style.top = (st1 + window.innerHeight - 253) + "px";
});